/*
 * @Author: Sam
 * @Date: 2025-04-27 15:42:50
 * @LastEditTime: 2025-10-09 10:51:09
 * @LastEditors: Sam
 */
import { useCallback } from "react";
import { ENVConfig } from "../configs/ENVConfig";

export const useApp = ()=>{

	/**获取示例应用token */
	const getToken = useCallback(async ()=>{

		//应用APP ID
		const APP_ID = ENVConfig.app.id;

		//应用APP SECRET
		const APP_SECRET = ENVConfig.app.secret;

		const fetchJSON = async (path:string)=>{
			const url = ENVConfig.API_BASE_URL + path;
			const response = await fetch(url);
			const jsonResult = await response.json();
			return jsonResult;
		}
		const tokenPath = '/bim-api/application-center/getToken?appId='+APP_ID+'&appSecret='+APP_SECRET;
        const { result:{access_token} } = await fetchJSON(tokenPath);
		return access_token as string;
	}, []);
	return { getToken };
}